<script>
var usedPositions = new Array();
<?$usedPositions = getUsedPositions($loggedInTeam->id);
$usedPositionCount = count($usedPositions);
for ($i = 0; $i < $usedPositionCount; $i++) {?>
usedPositions[<?echo $i?>] = "<?echo $usedPositions[$i]?>";
<?}?>
var pickFormSubmitted = false;
function validateSelections(frm) {
	if (!pickFormSubmitted) {
		count = 0;
		
		if (frm.newPlayer.value == "") {
			alert("No player has been selected");
			return;
		}
		else if (frm.playerPosition.selectedIndex <= 0) {
			alert("Player position required!");
			return;
		}
		pickFormSubmitted = true;
                frm.skipMyPick.value = "false";
		frm.submit();
	}
}
function skipMyPickSubmit(frm) {
   frm.skipMyPick.value = "true";
   pickFormSubmitted = true;
   frm.submit();
}
var playerAdded = false;
function addNewPlayer(frm) {
        if (playerAdded) {
           return;
        }
	var player = frm.availPlayers.options[frm.availPlayers.selectedIndex];
	document.getElementById('newPlayerDiv').innerHTML += player.text;
	frm.newPlayer.value = player.value;
	frm.availPlayers.options[frm.availPlayers.selectedIndex] = null;
        playerAdded = true;
}
function resetLists(frm) {
	frm.availPlayers.options.length = 0;
	document.getElementById('newPlayerDiv').innerHTML = "";
	frm.newPlayer.value = "";
	populateSelect(frm);
        playerAdded = false;
}
function populatePositions() {
	for (i=0; i<positions.length;i++) {
		var foundIt = false;
		for (j=0; j<usedPositions.length;j++) {
			if (positions[i].code == usedPositions[j]) {
				foundIt = true;
				break;
			}
		}
		
		if (!foundIt) {
			document.getElementById('playerPosition').options[document.getElementById('playerPosition').options.length] = new Option(positions[i].label, positions[i].code);
		}
	}
}
function Position(code, label) {
	this.label = label;
	this.code = code;
} 
var positions = new Array();
positions[0] = new Position('LBP', 'Back Pocket(Left)');
positions[1] = new Position('FB', 'Full Back');
positions[2] = new Position('RBP', 'Back Pocket(Right)');
positions[3] = new Position('LHBF', 'Half Back Flank(Left)');
positions[4] = new Position('CHB', 'Centre Half Back');
positions[5] = new Position('RHBF', 'Half Back Flank(Right)');			
positions[6] = new Position('LW', 'Wing(Left)');
positions[7] = new Position('C', 'Centre');
positions[8] = new Position('RW', 'Wing(Right)');
positions[9] = new Position('LHFF', 'Half Forward Flank(Left)');
positions[10] = new Position('CHF', 'Centre Half Forward');
positions[11] = new Position('RHFF', 'Half Forward Flank(Right)');
positions[12] = new Position('LFP', 'Forward Pocket(Left)');
positions[13] = new Position('FF', 'Full Forward');
positions[14] = new Position('RFP', 'Forward Pocket(Right)');
positions[15] = new Position('R', 'Ruck');
positions[16] = new Position('F1', 'Follower 1');
positions[17] = new Position('F2', 'Follower 2');
</script>

<form id="reqFormForMyPick" method="post" action="../makePickAndPref/submitMakeMyPick.php">
<input type="hidden" name="teamId" />
<input type="hidden" name="skipMyPick" value="false" />
<table>
	<tr>
		<td></td>
		<td><input type="button" value="Skip My Pick" onclick="skipMyPickSubmit(this.form)"></td>
	</tr>
	<tr>
		<td></td>
		<td><input type="text" onkeyup="filterSelect(this.value, this.form, false)"></input>&nbsp;Start typing name to filter list</td>
	</tr>
	<tr>
		<td colspan="2">
		<table>
		<tr>
		<td>
			<select name="availPlayers" size="20">
			</select> 
		</td>
		<td><input type="button" value="Add" onclick="addNewPlayer(this.form)" class="buttonStyle"><br><input type="button" value="Reset" onclick="resetLists(this.form)" class="buttonStyle"></td>
		</tr>
		<tr>
		<td valign="top"><b>New Players</b><br><input type="hidden" name="newPlayer"></input><div id="newPlayerDiv" /></td>
		</tr>
		<tr>
		<td valign="top">Position:
		<select name="playerPosition" id="playerPosition">
			<option value="">Select Position</option>
			<option value="RES">Reserve</option>
		</select></td>
		</tr>
		<tr>
		<td colspan="3"><input type="button" class="buttonStyle" value="Submit" onclick="validateSelections(this.form)" /></td>
		</tr>		
		</table>
	</tr>
</table>
</form>

<script>populateSelect(document.getElementById("reqFormForMyPick"), false);populatePositions();</script>